<?php


namespace app\index\controller;



use app\common\controller\UserController;
use app\common\model\EmployPurchase;
use app\common\model\Model;

class Purchase extends UserController
{

    /**
     * 编辑采购
     */
    function edit(){
        $param = input();
        $param["server_id"] = $this->getServerId();
        if( $param["id"] ){
            $data = EmployPurchase::simpleEdit($param);
        }else{
            $data = EmployPurchase::simpleAdd($param);
        }
        $this->result_success($data);
    }

    /**
     * 删除采购
     */
    function del(){
        $ids = input("ids");
        if(!is_array($ids)){
            $ids = [$ids];
        }
        $data = EmployPurchase::simpleDelete([
            "query"=>function(Model $query) use($ids){
                $query->whereIn("id",$ids);
            }
        ]);
        $this->result_success($data);
    }


    /**
     * 我的简单列表
     */
    function my_simple_list(){
        $server_id = $this->getServerId();
        $data = EmployPurchase::simpleList([
            "query"=>function(Model $query)use($server_id){
                $query->where(["server_id"=>$server_id]);
            }
        ]);
        $this->result_success($data);
    }

    /**
     * 获取一个采购
     */
    function one(){
        $good_id = input("good_id");
        $data = EmployPurchase::simpleOne(["id"=>$good_id]);
        $this->result_success($data);
    }

    /**
     * 所有采购
     */
    function simple_list(){
        $data = EmployPurchase::simpleList([
            "query"=>function($query){
            }
        ]);
        $this->result_success($data);
    }
}